import Vue from "vue";
import Router from "vue-router";
// import HelloWorld from '@/components/HelloWorld'
import getValidate from "@/views/login";
import Login from "@/views/login/login";
import VerificationCode from "@/views/verificationCode/verificationCode";
import Details from "@/views/index/details/details";
import RightsInterests from "@/components/rightsInterests/rightsInterests";
import Record from "@/components/record/record";
import ContentPage from "@/views/index/content/content";
import content from "@/views/content";
import Home from "@/views/home";
import wxstate from '@/views/index/state';
import rightList from "@/views/index/rightList";
import rightListDetail from '@/views/index/rightDetail';
import wxcash from '@/views/index/wx';
import ykcash from '@/views/index/yk';
import ykcashSure from '@/views/index/ykSure';
import ykdetailed from '@/views/index/ykdetailed';
import ykdetails from '@/views/index/ykdetails';
import wxdetail from '@/views/index/wxdetail';
Vue.use(Router);

let router = new Router({
  linkActiveClass: "on",
  mode: "history",
  base: "/oilCardMobile",
  routes: [
    {
      path: "/",
      name: "oil",
      component: getValidate
    },
    {
      path: "/getValidate",
      name: "getValidate",
      component: getValidate
    },
    {
      path: "/login",
      name: "login",
      component: Login
    },
    {
      path: "/home",
      name: "home",
      component: Home
    },
    {
      path: "/verificationCode",
      name: "verificationCode",
      component: VerificationCode
    },
    {
      path: "/index/content",
      name: "content",
      component: ContentPage,
      children: [
        {
          path: "/index/content/rightList",
          name: "rightList",
          component: rightList
        },
        {
          path: "/index/content/rightsInterests",
          name: "rightsInterests",
          component: RightsInterests
        },
        {
          path: "/index/content/record",
          name: "record",
          component: Record
        }
      ]
    },
    {
      path: "/index/content/rightListDetail",
      name: "rightListDetail",
      component: rightListDetail
    },
    {
      path: "/index/detailsContent",
      name: "detailsContent",
      component: content,
      redirect: "/index/details",
      children: [
        {
          path: "/index/details",
          name: "details",
          component: Details
        }
      ]
    },
    {
      path: "/index/wxstate",
      name: "wxstate",
      component: wxstate
    },
    {
      path: "/index/wxcash",
      name: "wxcash",
      component: wxcash
    },
    {
      path: "/index/ykcash",
      name: "ykcash",
      component: ykcash
    },
    {
      path: "/index/ykcashSure",
      name: "ykcashSure",
      component: ykcashSure
    },
    {
      path: "/index/ykdetailed",
      name: "ykdetailed",
      component: ykdetailed //油卡明细
    },
    {
      path: "/index/ykdetails",
      name: "ykdetails",
      component: ykdetails
    },
    {
      path: "/index/wxdetail",
      name: "wxdetail",
      component: wxdetail
    }
  ]
});
router.beforeEach((to, from, next) => {
  if (to.matched.some(item => item.meta.requiresAuth)) {
    //如果是需要登录的，执行....
    let info = JSON.parse(sessionStorage.getItem("statusCode"));
    if (info !== 5002 && info !== 5003) {
      // 已经登录
      next();
    } else if (info == 5001) {
      router.push({
        path: "/login",
        query: {
          redirect: to.path.slice(1)
        }
      });
    } else {
    }
  } else {
    next();
  }
});
export default router;
